/*
 * @Author: lh lh7676776@163.com
 * @Date: 2024-05-27 15:31:15
 * @LastEditors: lh lh7676776@163.com
 * @LastEditTime: 2024-05-29 15:37:18
 * @FilePath: \xm\poster-node\serve.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express')
const bodyParser = require('body-parser')
var jwt = require('jsonwebtoken');
const multer = require('multer');
const path = require('path');
const secret = 'jintiantianqizhenhao'
const user = [{
    username: 'admin',
    password: '123'
  },
  {
    username: 'admin1',
    password: '123'
  },
]
const navidata = [{
    title: '精选推荐',
    data: [{
        type: 2,
        image: [
          'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
          'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
          'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
          'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
          'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        ],
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: [
          'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
          'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
          'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
          'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
          'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        ],
        type: 2
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.7KW5GT7NQ8yUGlBbCHEm0gHaNK?rs=1&pid=ImgDetMain',
        type: 1
      },
    ]
  },
  {
    title: '热点关注',
    data: [{
        image: '//video-1251586368.file.myqcloud.com//tencent/TEMPLATE/d2191836b31f4ce8b9ac36036c09aeab.mp4',
        type: 3
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
      {
        image: 'https://img95.699pic.com/photo/50165/7667.jpg_wh860.jpg',
        type: 1
      },
    ]
  },
  {
    title: '儿童节',
    data: [{
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/2107631312/3178897554.jpg',
        type: 1
      },
    ]
  },
  {
    title: '高考加油',
    data: [{
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
      {
        image: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.xw5wjBwOqpdG8ldIWxbWzwHaE8?rs=1&pid=ImgDetMain',
        type: 1
      },
    ]
  },
  {
    title: '端午节',
    data: [{
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
      {
        image: 'https://www.keaitupian.cn/cjpic/frombd/2/253/1935056331/3997880040.jpg',
        type: 1
      },
    ]
  },
  {
    title: 'hellp',
    data: [{
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
      {
        image: 'https://ts1.cn.mm.bing.net/th/id/R-C.fc43da2eb56eeae121e644291f50a7bb?rik=vpKulh%2bvMwM9%2fQ&riu=http%3a%2f%2fpic.bizhi360.com%2fbbpic%2f10%2f7110.jpg&ehk=IGqrno2FZ5SKEzZw2tOdfL7p0cB2UVZGeZ2IsArmHaM%3d&risl=&pid=ImgRaw&r=0',
        type: 1
      },
    ]
  },
]
const app = express()
const bodyJson = bodyParser.json()
const port = 3000

// 设置静态资源的读取目录
app.use(express.static(path.join(__dirname, '/uploads')))


app.get('/getnavidata', (req, res) => {
  res.send(navidata)
})
app.get('/cs', (req, res) => {
  res.send({
    title: '额外个'
  })
})
app.post('/login', bodyJson, (req, res) => {
  let {
    username,
    password
  } = req.body
  console.log(username, password)
  let es = user.filter(item => item.username == username && item.password == password)
  console.log(es)
  if (es.length > 0) {
    res.send({
      data: es,
      code: 200,
      token: jwt.sign({
        data: 'foobar'
      }, secret, {
        expiresIn: '1d'
      }),
      refistoken: jwt.sign({
        data: 'foobar'
      }, secret, {
        expiresIn: '7d'
      }),
    })
  } else {
    res.send({
      code: 500,
      msg: '登录失败'
    })
  }

})


// 设置存储配置
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/') // 确保这个文件夹已经存在
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now() + `.${file.originalname.split('.')[1]}`)
  }
})

const upload = multer({
  storage: storage
});

// 单文件上传
app.post('/upload', upload.single('file'), (req, res) => {
  const file = req.file;
  // console.log(file, 'file')
  if (!file) {
    return res.status(400).send('No file uploaded.');
  }
  res.send({
    // code: 200,
    msg: `http://localhost:3000/${file.filename}`,
    // data: file
  });
});




app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})